package com.mhc.suzuki.controller;

import com.mhc.suzuki.constant.ErrorCodeEnum;
import com.mhc.suzuki.service.CarInfoService;
import com.mhc.suzuki.vo.CarInfoVO;
import com.subaru.common.entity.BizResult;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by kanon on 17/8/11 19:18.
 */
@Slf4j
@RestController
@RequestMapping(value = "/carinfo")
public class CarInfoController {

    @Autowired
    private CarInfoService carInfoService;

    /**
     * 根据订单号获取车辆信息
     *
     * @param orderNO
     * @return
     */
    @ApiOperation(value = "根据订单号获取车辆信息", notes = "")
    @RequestMapping(value = {"/{orderNO}"}, method = RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orderNO", paramType = "path", value = "订单号", required = true),
    })
    public BizResult<CarInfoVO> getCarInfoByOrderNO(@PathVariable String orderNO) {
        try {
            CarInfoVO carInfoVO = carInfoService.getCarInfo(orderNO);
            if (carInfoVO != null) {
                return BizResult.create(carInfoVO, ErrorCodeEnum.SUCCESS.getErrCode(), ErrorCodeEnum.SUCCESS.getErrMsg());
            } else {
                return BizResult.create(null, ErrorCodeEnum.NO_DATA.getErrCode(), ErrorCodeEnum.NO_DATA.getErrMsg());
            }
        } catch (Exception e) {
            log.error("error in getCarInfoByOrderNO", e);
            return BizResult.create(ErrorCodeEnum.SELECT_FAILURE.getErrCode(), ErrorCodeEnum.SELECT_FAILURE.getErrMsg());
        }
    }

}